//206
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode tmp = head.next;
        head.next = null;
        return digui(head, tmp);
    }

    public ListNode digui(ListNode head1, ListNode head) {
        if (head == null) {
            return head1;
        }
        ListNode tmp = head.next;
        head.next = head1;
        return digui(head, tmp);
    }
}
描述
输入一个整数，计算它的位数。如果输入的整数不大于0则输出这个数
输入描述：
一个整数
输出描述：
整数的位数


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        scan.close();

        //write code here......
        int count = 0;
        if (num <= 0){
            System.out.println(num);
        }else{
            while(num != 0){
                num /= 10;
                count++;
            }
        }
        System.out.println(count);
    }
}
//1833
class Solution {
    public int maxIceCream(int[] costs, int coins) {
        sort(costs);
        if (coins < costs[0]) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < costs.length; i++) {
            coins -= costs[i];
            if (coins >= 0) {
                count++;
            } 
            else {
                return count;
            }
        }
        return count;
    }

    public void sort(int[] costs) {
        int[] arr = new int[100000];
        for (int i = 0; i < costs.length; i++) {
            arr[costs[i]-1]++;
        }

        for (int i = 0, j = 0; i < 100000 && j < costs.length; i++) {
            while (arr[i]-- != 0) {
                costs[j++] = i+1;
            }
        }
    }
}

